package com.sugon.modules.sparepart.model.vo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.sugon.entity.SparePartRequDetailEntity;
import lombok.Data;

/**
 * @author ： YuXD
 * @description： 设备需求计划条目VO
 * @date ： 2020-08-31 下午 2:35
 * @version: 1.0
 */
@Data
public class SparePartRequDetailVO extends SparePartRequDetailEntity {

    /**
     * 计划类别，分为过程计划(PROCESS)和终版计划(RESULT)
     * 过程计划为最终计划提供生成
     */
    private String planType;

    @Excel(name = "计划类别", width = 10, orderNum = "0")
    private String planTypeDesc;

    public String getPlanTypeDesc() {
        if ("RESULT".equals(this.planType)) {
            return "终版计划";
        } else {
            return "过程计划";
        }
    }

    /**
     * 编制月份
     */
    @Excel(name = "编制月份", width = 10, orderNum = "1")
    private String organMonth;

    /**
     * 申请单位
     */
    @Excel(name = "申请单位", width = 20, orderNum = "1")
    private String applyUnit;

    /**
     * 提出人
     */
    @Excel(name = "提出人", width = 10, orderNum = "2")
    private String organUserName;

    /**
     * 备件名称
     */
    @Excel(name = "备件名称", width = 20, orderNum = "3")
    private String materialName;

    /**
     * ERP编码
     */
    @Excel(name = "ERP编码", width = 20, orderNum = "5")
    private String erpCode;

    /**
     * 备件规格
     */
    @Excel(name = "规格型号", width = 35, orderNum = "6")
    private String spec;

    /**
     * 计量单位
     */
    private String unit;

    /**
     * ABC类
     */
    private String planAbc;

    /**
     * 安全库存数
     */
    private String safeNum;

    /**
     * 备件安装位置
     */
    private String installPosition;

    /**
     * 备件类型：0: '通用', 1: '专用'
     */
    private String type;

    private String typeDesc;

    /**
     * 车间代码
     */
    private String cjCode;

    public String getTypeDesc() {
        if (StrUtil.isNotEmpty(type)) {
            if ("0".equals(type)) {
                return "通用";
            } else if ("1".equals(type)) {
                return "专用";
            }
        }
        return "";
    }


    /**
     * 备件库存数
     */
    private String stockNum;

    /**
     * 备件在途数
     * <p>
     * 该备件的所有需求计划的在途数总和
     */
    private String spareTransitNum;

    /**
     * 到货周期
     */
    private Long deliveryCycle;

    public Long getDeliveryCycle() {
        if (getActualArriveTime() != null && getOrderGenerateTime() != null) {
            return DateUtil.betweenDay(getOrderGenerateTime(), getActualArriveTime(), true);
        }
        return null;
    }

    /**
     * 制造商
     */
    private String producor;

}
